package com.hangzhou.xyj.ui.adapter;

import android.graphics.drawable.Drawable;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.manager.IntentManager;
import com.hangzhou.xyj.model.UserModel;
import com.hangzhou.xyj.model.type.EUserType;
import com.hangzhou.xyj.ui.adapter.base.BaseLoadingAdapter;
import com.hangzhou.xyj.ui.widget.CircleImageView;
import com.hangzhou.xyj.ui.widget.views.MyTextView;
import com.hangzhou.xyj.utils.PublicUtil;

import java.util.List;

public class MyFansAdapter extends BaseLoadingAdapter<UserModel> {


    public MyFansAdapter(RecyclerView recyclerView, List<UserModel> list) {
        super(recyclerView, list);
    }

    @Override
    public void onBindNormalViewHolder(ViewHolder viewHolder, final int position) {
        //绑定数据
        ((MyFansViewHolder) viewHolder).setData(mDataList.get(position));
        ((MyFansViewHolder) viewHolder).itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UserModel user = mDataList.get(position);
                IntentManager.getInstance().goExpertInfoActivity(mContext, user.getUser_id(),
                        user.getNickName(), user.getUserType());
            }
        });
    }

    @Override
    public ViewHolder onCreateNormalViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(
                R.layout.layout_myfocus_item, null);
        return new MyFansViewHolder(view);
    }

    private class MyFansViewHolder extends ViewHolder {

        MyTextView mTvName;
        MyTextView mTvSign;
        CircleImageView mCivHeader;

        private MyFansViewHolder(View view) {
            super(view);
            mTvName = (MyTextView) view.findViewById(R.id.mtv_name);
            mTvSign = (MyTextView) view.findViewById(R.id.mtv_sign);
            mCivHeader = (CircleImageView) view.findViewById(R.id.civ_header);
        }

        /**
         * @param
         * @return
         * @Description 设置数据
         * @author yaohuix
         * @date 2016/3/2 14:10
         */
        public void setData(UserModel user) {
            mTvName.setText(user.getNickName());
            mTvSign.setText(user.getSignature());
            mCivHeader.displayImage(user.getHeadPic());
            EUserType userType = user.getUserType();
            Drawable drawable = PublicUtil.getAuthenIconDrawable(mContext, userType);
            mTvName.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
        }
    }
}
